package com.bwda.dsrs.systemservice.service.impl;


import com.bwda.dsrs.systemservice.domain.condition.role.RoleCondition;
import com.bwda.dsrs.systemservice.domain.condition.userrole.UserRoleCondition;
import com.bwda.dsrs.systemservice.domain.po.role.RolePo;
import com.bwda.dsrs.systemservice.domain.po.userrole.UserRolePo;
import com.bwda.dsrs.systemservice.domain.vo.role.RoleVo;
import com.bwda.dsrs.systemservice.mapper.RoleMapper;
import com.bwda.dsrs.systemservice.service.RoleService;
import com.bwda.dsrs.systemservice.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author youzhen
 */
@Service
public class RoleServiceImpl extends AbstractBaseServiceImpl<RolePo, RoleCondition, RoleMapper> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private RoleService roleService;

    @Override
    public List<RolePo> queryRoleList() {
        return roleMapper.queryRoleList();
    }

    @Override
    public List<RolePo> queryUserRoleList(String userCode) {
        List<RolePo> result = null;
        UserRoleCondition userRoleCondition = new UserRoleCondition();
        userRoleCondition.setUserCode(userCode);
        List<UserRolePo> poList = userRoleService.queryList(userRoleCondition);
        if(poList != null && !poList.isEmpty()){
            List<Integer> idList = new ArrayList<Integer>();
            for(UserRolePo userRolePo : poList){
                idList.add(userRolePo.getRoleId());
            }
            RoleCondition roleCondition = new RoleCondition();
            roleCondition.setIdList(idList);
            result = roleService.queryList(roleCondition);
        }
        return result;
    }

    @Override
    public List<RolePo> queryRoleByCode(String userCode) {
        return roleMapper.queryRoleByCode(userCode);
    }
}